//
//  LinkInfo.m
//  RoutingEvaluator
//
//  Created by Christopher Kemsley on 4/12/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#import "LinkInfo.hpp"

NamespaceBegin



LinkInfo*	LinkInfo :: createLinkInfo	( CostAlgorithm const & algorithm , NodeInfo * node1 , NodeInfo * node2 )
	{
	return new LinkInfo ( algorithm , node1 , node2 ) ;
	}

Float64	LinkInfo :: distance ()
	{
	return endpoint1 -> distanceFromNode ( endpoint2 ) ;
	}
Float64	LinkInfo :: cost ()
	{
	return algorithm . costOfTransmission ( endpoint1 , endpoint2 ) ;
	}
LinkInfo :: LinkInfo	( CostAlgorithm const & al , NodeInfo * n1 , NodeInfo * n2 )
:	Object()
,	endpoint1 ( n1 )
,	endpoint2 ( n2 )
,	algorithm ( al )
	{
	
	}


LinkInfoSet*	LinkInfoSet :: createSetWithNodes	( CostAlgorithm const & algorithm , NodeInfoSet * set )
	{
	std::vector<LinkInfo*>	them ;
	
	std::vector<NodeInfo*>::const_iterator	here1	=	set->nodes().begin() ;
	std::vector<NodeInfo*>::const_iterator	here2 ;
	std::vector<NodeInfo*>::const_iterator	end		=	set->nodes().end() ;
	while ( here1 < end )
		{
		NodeInfo * node1 = *(here1++) ;
		
		here2 = here1 ;
		while ( here2 < end )
			{
			NodeInfo * node2 = *(here2++) ;
			
			LinkInfo * cost = new LinkInfo ( algorithm , node1 , node2 ) ;
			them . push_back ( cost ) ;
			}
		}
	
	return new LinkInfoSet ( them ) ;
	}



std::vector<LinkInfo*> const&	LinkInfoSet :: links ()
	{
	return mCosts ;
	}

LinkInfoSet :: LinkInfoSet ( std::vector<LinkInfo*> const & inCosts )
:	mCosts ( inCosts ) { }


NamespaceEnd
